package com.cmd.driver;


import com.alibaba.fastjson.JSONObject;
import com.mgr.UserOrderMgr;
import com.player.DriverUser;
import com.player.User;
import com.player.WorldMgr;
import com.protocol.Protocol;
import com.qy.util.StaticData;
import com.util.AbstractCommand;
import com.util.PBMessage;

/**
 * 
 * 司机移动
 * @author zwl
 * 2018年2月1日
 */
public class DriverMoveCMD  extends AbstractCommand{

	@Override
	public void execute(User user, PBMessage packet) throws Exception {
		/*
		 * 获取坐标点
		 * 生成一条坐标信息插入队列中
		 * 更新司机的坐标
		 * 同步给车主
		 */
		JSONObject reJs = new JSONObject();
		reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
		JSONObject param = packet.getMessage();
		if(!param.containsKey("point")){
			reJs.put(StaticData.reKey.code.getKey(), StaticData.codeType.param_error.getType());
			user.sendPacket(reJs);
			return;
		}
		DriverUser driverUser = (DriverUser) user;
		if(driverUser.getServerOrder()==null){
			reJs.put(StaticData.reKey.code.getKey(), StaticData.codeType.NOT_END_SEVER.getType());
			user.sendPacket(reJs);
			return; 
		}
		String myPoint = param.getString("point");
		/*
		 *  生成一条坐标信息插入队列中
		 */
		/*
		 * 更新司机的坐标
		 */
		driverUser.setMyPoint(myPoint);
		reJs.put(StaticData.reKey.code.getKey(), StaticData.codeType.ok.getType());
		reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
		user.sendPacket(reJs);
		/*
		 * 同步给车主
		 */
		int cUserId = UserOrderMgr.getUserIdByOrderId(driverUser.getServerOrder().getOrderId());
		if(WorldMgr.isExist(cUserId, StaticData.userType.COMMON_USER.getType())){
			JSONObject sReJs = new JSONObject();
			sReJs.put(StaticData.reKey.cmd.getKey(), Protocol.C_MOVE);
			sReJs.put("point", myPoint);
			User oUser = WorldMgr.getGamePlayer(cUserId,StaticData.userType.COMMON_USER.getType());
			oUser.sendPacket(sReJs);
		}
		return;
	}

}
